package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.CaseReimbType;
import com.ktgj.customer.service.ICaseReimbTypeService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 赔偿类型Controller
 * 
 * @author ruoyi
 * @date 2022-05-26
 */
@RestController
@RequestMapping("/type")
public class CaseReimbTypeController extends BaseController
{
    @Autowired
    private ICaseReimbTypeService caseReimbTypeService;

    /**
     * 查询赔偿类型列表
     */
    @PreAuthorize(hasPermi = "system:type:list")
    @GetMapping("/list")
    public TableDataInfo list(CaseReimbType caseReimbType)
    {
        startPage();
        List<CaseReimbType> list = caseReimbTypeService.selectCaseReimbTypeList(caseReimbType);
        return getDataTable(list);
    }

    /**
     * 查询赔偿类型列表
     */
    @PostMapping("/caseReimbTypeList")
    public AjaxResult caseReimbTypeList()
    {
        List<CaseReimbType> list = caseReimbTypeService.selectCaseReimbTypeList(null);
        return AjaxResult.success(list);
    }

    /**
     * 导出赔偿类型列表
     */
    @PreAuthorize(hasPermi = "system:type:export")
    @Log(title = "赔偿类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaseReimbType caseReimbType) throws IOException
    {
        List<CaseReimbType> list = caseReimbTypeService.selectCaseReimbTypeList(caseReimbType);
        ExcelUtil<CaseReimbType> util = new ExcelUtil<CaseReimbType>(CaseReimbType.class);
        util.exportExcel(response, list, "赔偿类型数据");
    }

    /**
     * 获取赔偿类型详细信息
     */
    @PreAuthorize(hasPermi = "system:type:query")
    @GetMapping(value = "/{reimbTypeId}")
    public AjaxResult getInfo(@PathVariable("reimbTypeId") Long reimbTypeId)
    {
        return AjaxResult.success(caseReimbTypeService.selectCaseReimbTypeById(reimbTypeId));
    }

    /**
     * 新增赔偿类型
     */
    @PreAuthorize(hasPermi = "system:type:add")
    @Log(title = "赔偿类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaseReimbType caseReimbType)
    {
        return toAjax(caseReimbTypeService.insertCaseReimbType(caseReimbType));
    }

    /**
     * 修改赔偿类型
     */
    @PreAuthorize(hasPermi = "system:type:edit")
    @Log(title = "赔偿类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaseReimbType caseReimbType)
    {
        return toAjax(caseReimbTypeService.updateCaseReimbType(caseReimbType));
    }

    /**
     * 删除赔偿类型
     */
    @PreAuthorize(hasPermi = "system:type:remove")
    @Log(title = "赔偿类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reimbTypeIds}")
    public AjaxResult remove(@PathVariable Long[] reimbTypeIds)
    {
        return toAjax(caseReimbTypeService.deleteCaseReimbTypeByIds(reimbTypeIds));
    }
}
